const ipcRenderer = window.electron.ipcRenderer;
let callback: (info: { sid: string, nick: string, uid: string }) => void;
let exePathCallback: (path: string) => void;
ipcRenderer.on('sid', (_e: any, args: any) => {
    args.nick = unescape(args.nick);
    callback && callback(args);
});
ipcRenderer.on('exe', (_e: any, args: any) => {
    exePathCallback && exePathCallback(args);
});

const getUserInfo = async (opts?: { username: string, password: string }): Promise<{ sid: string, nick: string, uid: string }> => {
    return new Promise((res) => {
        callback = (info) => {
            res(info);
        };
        ipcRenderer.send('sid', opts);
    });
}

const getExEPath = async () => {
    return new Promise<string>((res) => {
        exePathCallback = (path) => {
            res(path);
        }
        ipcRenderer.send('exe');

    })
}

export { getUserInfo, getExEPath };


